<script setup lang="ts">
import {ref, computed} from 'vue'

function roundToDecimalPlaces(num: number, places: number): number {
  const multiplier = Math.pow(10, places);
  return Math.floor(num * multiplier) / multiplier;
}

const pOfe = computed(() => {
  let e;
  e = 1 - Math.pow(1 - pOfsingle.value / 100, nOftry.value)
  return roundToDecimalPlaces(e * 100, 3)
})
const pOfsingle = ref(0)
const nOftry = ref(1)
</script>

<template>
  <el-row>
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <el-text class="mx-1" size="large">单次事件概率：</el-text>
        <!--        <span class="demonstration">Default value</span>-->
      </div>
    </el-col>
    <el-col :span="18">
      <div class="grid-content ep-bg-purple-light">
        <div class="slider-demo-block">
          <el-slider
              v-model="pOfsingle"
              show-input
              :min="0.001"
              :max="99.999"
              :step="0.001"
          />
        </div>
      </div>
    </el-col>
  </el-row>

  <el-row>
    <el-col :span="6">
      <div class="grid-content ep-bg-purple">
        <el-text class="mx-1" size="large">尝试次数：</el-text>
        <!--        <span class="demonstration">Default value</span>-->
      </div>
    </el-col>
    <el-col :span="18">
      <div class="grid-content ep-bg-purple-light">
        <el-input-number
            v-model="nOftry"
            :step="1"
            step-strictly
            min="1"
            max="2147483647"
            style="width: 100%"/>
      </div>
    </el-col>
  </el-row>


  <div class="demo-progress">
    <span style="font-size: 18px">
      成功率
    </span>
    <el-progress :text-inside="true" :percentage="pOfe" :stroke-width="30" striped striped-flow/>
  </div>
  <!--  <el-row style="margin-top: 5px">-->
  <!--    <el-col :span="24">-->
  <!--      <div class="grid-content ep-bg-purple">-->
  <!--        <el-statistic title="理论达到期望概率所需次数" :value="nOftry"/>-->
  <!--      </div>-->
  <!--    </el-col>-->
  <!--  </el-row>-->


</template>

<style scoped>
.demo-progress .el-progress--line {
  margin-top: 10px;
  max-width: 95%;
  margin-left: 2.5%;
}
/deep/.el-progress-bar__innerText{
  color: #000000;
  font-size: 16px;
  font-weight: bold;
}

.centered-input .el-input__inner {
  text-align: center;
  vertical-align: middle;
  /* 设置宽度和高度 */
  //width: 200px;
  //height: 100px;
}

.el-statistic {
  --el-statistic-content-font-size: 40px;
  --el-statistic-title-font-size: 18px;
}

.el-row {
  margin-bottom: 0px;
  margin-left: 4px;
  margin-right: 4px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
  margin-top: 2px;
  margin-bottom: 2px;
}

.ep-bg-purple {
  //background: #d3dce6;
}

.ep-bg-purple-light {
  //background: #afaf50;
}

.grid-content {
  display: flex;
  border-radius: 4px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
}

.slider-demo-block {
  display: flex;
  width: 100%;


}

.slider-demo-block .el-slider {
  margin-top: 0;
  margin-left: 12px;
}
</style>